<?php
/**
 * Pages_AdminController
 * 
 * @author
 * @version 
 */
class Pages_IndexController extends Zend_Controller_Action {
	/**
	 * The default action - show the home page
	 */
	public function indexAction() {
		$model = new Zen_List('pages_item');
		if ($this->_hasParam ( 'alias' )) {
			$alias = trim ( $this->_getParam ( 'alias' ) );
			$alias = preg_replace ('/^\\/+/','',$alias);
			$alias = "/".preg_replace ( '/\\/+$/', '', $alias ) . '/';
			$alias = preg_replace ( '/&frasl;/', '/', $alias );
			 
			$page = $model->select()->getOne( "(`aliasfull`='" . $alias . "')" );
			
		} else {
			$page = $model->select()->getOne('`mode`=1');
		}
		
		if ($page) {
			if (! $this->view->title) {
				$this->view->title = $page['label'];
			}
			$cnf=Zend_Registry::get('cnf');
			if($page['mode']!=1){
				
				$canonical_link=$cnf->domen.$page['aliasfull'];			
			}else{
				$canonical_link=$cnf->domen;	
			}
			
			if(! Zend_Registry::isRegistered('cid')) Zend_Registry::set('cid', $page['id']);
			
			$this->view->text = $page ['text'];
			$this->view->label = $page ['label'];
			if (isset ( $page ['layout'] ) && ($page ['layout'] != 'index') && ($page ['layout'] != '')) {
				$this->_helper->layout ()->setLayout ( $page ['layout'] );
			}
			
			if ($this->_request->isXmlHttpRequest ()) {
				$this->_helper->layout ()->disableLayout ();
			}
		
		} else {
			$this->view->text = 'Страница не найдена';
		}
		$this->view->params = $this->_getAllParams ();
	}
	/*
	public function testAction() {
		$this->_helper->viewRenderer->setNoRender();
		$model = new Pages_Model_Tree() ;
		$model->copy();
		echo 1;
	}
	*/
}
